package com.mzj.saas.commons.exception.handle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mzj.saas.commons.exception.ErrorCode;
import com.mzj.saas.commons.exception.ServiceException;

/*@ControllerAdvice
public class ExceptionHandlerController {

	private static final Logger LOG = LoggerFactory.getLogger(ExceptionHandlerController.class);

	@ExceptionHandler(value = { Exception.class, RuntimeException.class,ServiceException.class })
	@ResponseBody
	public ResponseEntity<?> defaultErrorHandler(HttpServletRequest request, HttpServletResponse response, Exception ex) {

		HttpStatus status = HttpStatus.valueOf(response.getStatus());
		ResultVo<String> result = new ResultVo<>();
		result.setMsg(ex.getMessage());

		if (ex instanceof ServiceException) {
			ServiceException cex = (ServiceException) ex;
			result.setCode(cex.getCode());
			if (cex.getHttpStatus() != null) {
				status = cex.getHttpStatus();
			}
		} else {
			result.setCode(ErrorCode.UNEXPECTED.code());
			LOG.error(ex.getMessage(), ex);
		}

		return new ResponseEntity<>(result, status);
	}
}
*/
